package com.single.weblearn.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.single.weblearn.json.Buy;
import com.single.weblearn.json.Result;
import com.single.weblearn.meta.Trx;
import com.single.weblearn.service.ProductWebService;

@Controller
public class BuyController {
	@Autowired
	private ProductWebService service;
	@RequestMapping(value = "/settleAccount", method = RequestMethod.GET)
	public String settleAccount(HttpServletRequest request) {
	  	return "settleAccount";
	}

	@RequestMapping(value = "/api/buy", method = RequestMethod.POST)
	public ResponseEntity<Result> buy(@RequestBody List<Buy> list) {
		  Result rs = new Result();
		if(!list.isEmpty()){
			service.buyProduct(list);
			rs.setCode(200);
			 rs.setMessage("购买成功");
		}else{
			rs.setCode(404);
			 rs.setMessage("购买失败");
		}
        rs.setResult(true);
		return new ResponseEntity<Result>(rs,HttpStatus.OK);
	}
}
